import '@/assets/common.css'
import keyboard from '@/util/keyboard.js'

import menu from '@/view/menu.js'
import viewer from '@/view/viewer.js'
import resource from '@/view/resource.js'
import original from '@/view/original.js'
import moveBar from '@/util/moveBar.js'
import viewStatus from '@/util/viewStatus'

// 渲染
var _menu = new menu();
$('body').append(_menu.html);

var _resource = new resource();
$('body').append(_resource.html);

var _original = new original();
$('body').append(_original.html);
$('body').append(_original.markEle);

var _viewer = new viewer();
$('body').append(_viewer.html);

var _viewStatus = new viewStatus();
_viewStatus.setView(_viewer);
_viewStatus.setOptionsView(_resource);
_original.setViewStatus(_viewStatus);

new moveBar(_resource.moveBar, [
    { obj: _resource, getWidth: 'getChangeMoveBarOptions', changeEvent: 'changeMoveBarEvent', },
    { obj: _viewer, getWidth: 'getChangeMoveBarOptions', changeEvent: 'changeMoveBarEvent', },
]);

new moveBar(_original.moveBar, [
    { obj: _original, getWidth: 'getChangeMoveBarOptions', changeEvent: 'changeMoveBarEvent', },
    { obj: _viewer, getWidth: 'getChangeMoveBarOptions', changeEvent: 'changeMoveBarEventLeft', }
]);

_original.init();

// 快捷键按键处理
keyboard('ctrl+s', function () {
    console.log('Save');
});
keyboard('ctrl+r', function () {
    window.location.reload();
});
keyboard('ctrl+=', function () {
    _viewer.zoomAdd();
});
keyboard('ctrl+-', function () {
    _viewer.zoomMinus();
});
keyboard('ctrl+0', function () {
    _viewer.renderZoom();
});

setTimeout(function () {
    _viewer.zoomAdd();
    setTimeout(function () {
        _viewer.renderZoom();
    }, 100);
}, 100);

var preventDefault = (event) => {
    var typeOptions = event.target.toString();
    if (typeOptions === '[object HTMLBodyElement]') {
        event.preventDefault();
    };
};

document.onkeydown = preventDefault;
document.onkeypress = preventDefault;